package com.idbk.chargestation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.idbk.chargestation.R;

import java.util.List;

/**
 * 汽车车型适配器
 * @author liangzw
 *
 */

public class CarTypeAdapter extends BaseAdapter {

	private List<String> list;
	private LayoutInflater mInflater;
	private TextView tv;

	public CarTypeAdapter(List<String> list, Context context) {
		this.list = list;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String name = list.get(position);
		if(convertView == null) {
			convertView = mInflater.inflate(R.layout.item_car_types, parent, false);
			tv = (TextView) (convertView).findViewById(R.id.car_type);
			convertView.setTag(tv);
		} else {
			tv = (TextView) convertView.getTag();
		}
		tv.setText(name);
		return convertView;
	}

}
